package com.example.bailin.giftsay.sort.activity;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.baseclass.BaseActivity;
import com.example.bailin.giftsay.entity.RaidersDownEntity;
import com.example.bailin.giftsay.sort.LmClickListener;
import com.example.bailin.giftsay.sort.adapter.PinLeiAdapter;
import com.example.bailin.giftsay.tool.MyApp;
import com.example.bailin.giftsay.tool.NetTool;
import com.example.bailin.giftsay.tool.UrlProvide;

/**
 * Created by bailin on 16/8/19.
 *
 * 分类攻略 品类/对象点击查看全部跳转的页面
 */
public class PLorDXActivity extends BaseActivity implements View.OnClickListener {

    private TextView tv;
    private ImageView iv;
    private RecyclerView rv;

    @Override
    protected int setLayout() {
        return R.layout.activity_plordx;
    }

    @Override
    protected void initView() {
        iv = bindView(R.id.iv_plordx_return);
        tv = bindView(R.id.tv_plordx_id);
        rv = bindView(R.id.rv_plordx_id);
        iv.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        tool().getData(UrlProvide.RAIDERS_DOWN, RaidersDownEntity.class, new NetTool.NetInterface<RaidersDownEntity>() {
            @Override
            public void onSuccess(RaidersDownEntity raidersDownEntity) {
                Intent intent = getIntent();
                int index = intent.getIntExtra("index", 990);
                // adapter的参数如果不是0则显示全部  本参数显示全部
                PinLeiAdapter adapter = new PinLeiAdapter(998);
                GridLayoutManager manager = new GridLayoutManager(MyApp.getContext(), 2);
                int count = index == 1 ? 0 : 2; // 如果返回0则是品类 2是对象
                adapter.setI(count);
                adapter.setLmClickListener(new LmClickListener() {
                    @Override
                    public void onClick(int id, String title) {
                        Intent intent = new Intent(MyApp.getContext(), GLSkipActivity.class);
                        intent.putExtra("id", id);
                        intent.putExtra("title", title);
                        startActivity(intent);
                    }
                });
                adapter.setEntity(raidersDownEntity);
                rv.setLayoutManager(manager);
                rv.setAdapter(adapter);
                if (index == 1) {
                    tv.setText("品类");
                } else {
                    tv.setText("对象");
                }
            }

            @Override
            public void onError(String errorMsg) {
            }
        });
    }

    @Override
    public void onClick(View v) {
        finish();
    }


}
